package com.talent.service.iot.mqtt.model;

import com.talent.service.iot.mqtt.model.entity.TlTopic;
import com.talent.service.iot.mqtt.model.request.TlMqttPublishReq;
import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.MqttQoS;
import io.netty.handler.codec.mqtt.MqttVersion;

import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName：TlMqttSession
 * @Author: hszhou
 * @Date: 2024/11/28 15:40
 * @Description: mqtt的会话
 */
public class TlMqttSession {


    /**客户端标识*/
    private String clientId;
    /**通道*/
    private Channel channel;
    /**遗嘱消息的qos等级*/
    private MqttQoS qos;
    /**需要补发的qos1或qos2的消息 会话保留的时候保存*/
    private Set<Integer> publishMsgStore=new HashSet<>();
    /**从客户端收到的QoS 2消息，但还没有确认的                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              */
    private Set<Integer> pubrelMsgStore=new HashSet<>();
    /**是否断开清除会话状态*/
    private int cleanSession;
    /**遗嘱消息 在非正常断开后向订阅的主题发送*/
    private TlMqttPublishReq willMessage;
    /**订阅的主题*/
    private Set<TlTopic> topics =new HashSet<>();

    /**协议版本*/
    private MqttVersion mqttVersion;

    public MqttQoS getQos() {
        return qos;
    }

    public void setQos(MqttQoS qos) {
        this.qos = qos;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    public Channel getChannel() {
        return channel;
    }

    public Set<Integer> getPublishMsgStore() {
        return publishMsgStore;
    }

    public void setPublishMsgStore(Set<Integer> publishMsgStore) {
        this.publishMsgStore = publishMsgStore;
    }

    public Set<Integer> getPubrelMsgStore() {
        return pubrelMsgStore;
    }

    public void setPubrelMsgStore(Set<Integer> pubrelMsgStore) {
        this.pubrelMsgStore = pubrelMsgStore;
    }

    public int getCleanSession() {
        return cleanSession;
    }

    public void setCleanSession(int cleanSession) {
        this.cleanSession = cleanSession;
    }

    public TlMqttPublishReq getWillMessage() {
        return willMessage;
    }

    public void setWillMessage(TlMqttPublishReq willMessage) {
        this.willMessage = willMessage;
    }

    public Set<TlTopic> getTopics() {

        return topics;
    }

    public void setTopics(Set<TlTopic> topics) {

        this.topics = topics;
    }

    public MqttVersion getMqttVersion() {
        return mqttVersion;
    }

    public void setMqttVersion(MqttVersion mqttVersion) {
        this.mqttVersion = mqttVersion;
    }


    public static TlMqttSession of(String clientId, Channel channel, int cleanSession){
        TlMqttSession session=new TlMqttSession();
        session.setClientId(clientId);
        session.setChannel(channel);
        session.setCleanSession(cleanSession);
        session.setMqttVersion(MqttVersion.MQTT_3_1_1);
        return session;
    }


}
